package com.iwhalecloud.bss.kite.cucc.service.util;

import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteObjectUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.dataservice.cache.DcPublicCache;
import com.iwhalecloud.bss.kite.dataservice.entity.DcPublic;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteProdInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.scene.attr.OperateInstAttrService;
import com.ztesoft.bss.common.util.SpringUtil;

import java.util.List;
import java.util.Objects;

public class ApnSpeedLimitUtil {
    /**
     * APN限速模板联动资费计划属性
     */
    public static void linkFeePlanAttr(KiteAttr kiteAttr, KiteInst inst, String sceneInstId, String apnSpeedLimitValue){
        OperateInstAttrService operateInstAttrService = SpringUtil.getBean(OperateInstAttrService.class);
        List<DcPublic> dcPublics = DcPublicCache.getByPcode("20220126101", kiteAttr.getFieldName(), apnSpeedLimitValue);
        if (KiteListUtils.isNotEmpty(dcPublics) && dcPublics.size()>0){
            String value = dcPublics.get(0).getCodea();
            operateInstAttrService.setAttrValue(inst, kiteAttr.getFieldName() , value, sceneInstId, null);
        }

    }
    /**
     * 取接入产品
     */
    public static void getKiteProdInst(KiteAttr attr, KiteInst inst, AttrData data){
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        //获取全部接入产品
        final KiteProdInst[] kiteProdInsts = new KiteProdInst[1];
        List<KiteProdInst> kiteProdInstList = querySceneInstService.listProdInsts(data.getSceneInstId());
        kiteProdInstList.stream().forEach(prodInst -> {
            if (KiteStringUtils.equals(prodInst.getSpecId(),"63249408")){
                kiteProdInsts[0] = prodInst;
            }
        });
        if (!KiteObjectUtils.isEmpty(kiteProdInsts) && !KiteObjectUtils.isEmpty(kiteProdInsts[0])) {
            KiteAttr kiteAttr = kiteProdInsts[0].getAttr("210005373");
            if (Objects.nonNull(kiteAttr) && KiteStringUtils.isNotEmpty(kiteAttr.getValue())) {
                ApnSpeedLimitUtil.linkFeePlanAttr(attr, inst, data.getSceneInstId(), kiteAttr.getValue());
            }
        }
    }
}
